$(function(){
	/**专业初始化*/
	$('#subjectId').combotree({
		url : 'subject/subjects',
		panelHeight:'150',
		onLoadSuccess : function (node, data) {
			 var t = $(this);
	  		 if(data){
			     $(data).each(function(index,d){
					if(this.state == 'closed'){
					    t.tree('expandAll');
					}
			     });
			}
		}
	});
	$('#oId_clear_btn').click(function(){
		$('#subjectId').combotree('clear');
	});
	
	/**知识点初始化*/
	$('#knowledgeId').combotree({
		url : 'knowledge/knowledges',
		panelHeight:'150',
		onLoadSuccess : function (node, data) {
			 var t = $(this);
	  		 if(data){
			     $(data).each(function(index,d){
					if(this.state == 'closed'){
					    t.tree('expandAll');
						//t.combotree('tree').tree("expandAll");
					}
			     });
			}
		}
	});
	
	var showPlayWin = function showPlayWin(attId) {
		parent.showEasyUiWindow('contentFrame', 'video/listByAttId.shtml?attId=' + attId, 'win', '视频播放', 625, 350, true);
	}
	/** 上传控件初始化 */
	fileUpload({
		positionId:'_fileupload',
		type: $('#fileType').length > 0 ? 'detail' : 'edit',
		initType:'ajax',
		ajaxUrl:'attachment/attachments.shtml',
		file_types : '*.wmv;*.flv;*.avi;*.mp4;*.doc;*.docx;*.xls;*.xlsx;*.txt;*.jpg;*.gif;*.png;*.ppt;*.pptx;',
		fileType : '*.wmv;*.flv;*.avi;*.mp4;*.doc;*.docx;*.xls;*.xlsx;*.txt;*.jpg;*.gif;*.png;*.ppt;*.pptx;',
		ajaxData:{bizId : $('#id').val(), attaType:'lessonPlan'},
		play_callback : showPlayWin
	});
	
	/*** 视频播放 */
	$('#moviePlay').click(function(){
		$('#form').ajaxSubmit({
			url : 'lessonplan/play',
			success : function(data) {
				if (!data.result) {
					$.messager.alert('提醒', data.msg,'info');
				} else {
					/*var redictUrl = "";
					redictUrl = redictUrl + '\\atta\\' + data.file_path;
					parent.showEasyUiWindow('contentFrame', 'video/list.shtml?filePath=' + redictUrl, 'win', '视频播放', 625, 350, true);*/
					var attId = data.attId;
					parent.showEasyUiWindow('contentFrame', 'video/listByAttId.shtml?attId=' + attId, 'win', '视频播放', 625, 350, true);
				}
			}
		});
	});
	
	/** 保存 */
	$('#btnSave').click(function(){
		$('#title').validatebox({
			required : true,
			missingMessage : '标题不能为空'
		});
		var valid = $('#form').form('validate');
		if(valid) {
			$('#form').ajaxSubmit({
				url : 'lessonplan/save',
				success : function(data) {
					if (!data.result) {
						$.messager.alert('提醒', data.msg,'info');
					} else {
						$.messager.alert('提醒', data.msg,'info', function() {
							$('#form').form('clear');
							parent.reSearch();
							parent.closeEasyUiWindow('win');
						});
					}
				}
			});
		}	
	});
	
	/** 取消 */
	$('#btnCancel').click(function(){
		$('#form').form('clear');
		parent.reSearch();
		parent.closeEasyUiWindow('win');
	});
});

